import 'package:base_flutter/base_flutter.dart';
import 'package:flustars_flutter3/flustars_flutter3.dart';
import 'package:flutter/material.dart';
import 'package:ls_work/a_yyt/models/policy_warning_entity.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/res/gaps.dart';
import 'package:ls_work/res/styles.dart';
import 'package:ls_work/widgets/load_image.dart';

import '../../util/flat_button.dart';



class PolicyCell extends StatelessWidget {
  final int? type;
  final PolicyWarningInfo? info;
  final VoidCallback? callBack;
  bool inBatchMode;
  bool isChoose;
  PolicyCell({Key? key, this.type, this.info, this.callBack,this.inBatchMode = false,this.isChoose = false});
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(10),
      width: double.infinity,
      margin: EdgeInsets.only(top: 15),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8),
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Gaps.vGap12,
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              Text(
                '${(info?.customerName??"").isNullOrEmpty()?"": info?.customerName??""}',
                style: TextStyles.textDark18,
              ),
              Gaps.hGap10,
              Expanded(
                child: Text(
                  (info?.customerName??"").isNullOrEmpty()?"":'${info?.floorNo??""}${info?.roomNo??""}',
                  style: TextStyles.textGray14,
                ),
              ),
              LoadAssetImage('elder/p_tag1'),
            ],
          ),
          if(!(info?.position??"").isNullOrEmpty()) ...[
            Gaps.vGap12,Text('报警位置：${info?.position??""}',style: TextStyles.textDark16,)],
          Gaps.vGap12,
          Icon(
            Icons.directions_walk,
            color: Colors.orange[200],
          ),
          Gaps.vGap12,
          Text(
            '首次呼叫： ${DateUtil.formatDateStr(info?.createdDate??"", format: 'MM-dd HH:mm:ss')}',
            style: TextStyles.textGray18,
          ),
          Gaps.vGap12,
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text.rich(TextSpan(children: [
                TextSpan(
                  text: '本次报警',
                  style: TextStyles.textGray18,
                ),
                TextSpan(
                  text: '${info?.callTimes??""}',
                  style: TextStyle(fontSize: 18, color: Colors.red),
                ),
                TextSpan(
                  text: '次呼叫',
                  style: TextStyles.textGray18,
                ),
              ])),

              inBatchMode?Icon(isChoose?Icons.check_box:Icons.check_box_outline_blank,color: isChoose?Colours.app_main:Colors.grey,):
              LoadAssetImage('elder/p_tag2'),

            ],
          ),
          Gaps.vGap12,
          Text(
            '最后呼叫： ${DateUtil.formatDateStr(info?.lastCallTime??"", format: 'MM-dd HH:mm:ss')}',
            style: TextStyles.textGray18,
          ),
          Gaps.vGap12,
          type == 0
              ? SizedBox()
              : Text(
                  '首次应答： ${DateUtil.formatDateStr(info?.answerTime??"", format: 'MM-dd HH:mm:ss')}',
                  style: TextStyles.textGray18,
                ),
          Gaps.vGap10,
          Gaps.vGap5,
          type == 1
              ? SizedBox():
              inBatchMode?SizedBox() : SizedBox(
                  height: 45,
                  width: double.infinity,
                  child: FlatsButton(
                    color: Colours.app_main,
                    onPressed: (){
                      if(callBack!=null){
                        callBack!();
                      }
                    },
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(8),
                    ),
                    child: Text(
                      '我知道了，准备处理',
                      style: TextStyle(fontSize: 16, color: Colors.white),
                    ),
                  ),
                ),
        ],
      ),
    );
  }
}
